package com.zw.factory;

import java.util.Map;

/**
 * Created by Zw on 2018/6/15.
 */
public class BeanFactory {

    private static BeanFactory beanFactory = new BeanFactory();

    private static Map<String,Bean> beanMap;
    private BeanFactory() {
    }
    public static BeanFactory getInstance(){
        return beanFactory;
    }
    //向外部提供一个getbean的方法
    //因为是工厂类，所以不依赖任何外部类，使用object作为返回类型
    public Object getBean(String beanName) {
        Bean bean = beanMap.get(beanName);
        String beanClass = bean.getBeanClass();
        try {
            return Class.forName(beanClass).newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
